import {
  validMobile
} from "@/pages/components/validate/validate";
import dayjs from 'dayjs'
import OrgSelect from '@/pages/system/org/orgSelect'
import RoleSelect from '@/pages/system/role/roleSelect'
export default {
  data() {
    return {
      targetUrl: '/users',
      template: {
        code: {
          title: '代码',
          value: ''
        },
        name: {
          title: '名称',
          value: ''
        },
        orgId: {
          title: '部门',
          component: {
            name: OrgSelect,
          }
        },
        roles: {
          title: '角色',
          component: {
            name: RoleSelect,
          }
        },
        mobile: {
          title: '手机',
          value: ''
        },
        mail: {
          title: '邮箱',
          value: ''
        },
        birthday: {
          title: '生日',
          value: '',
          component: {
            name: "el-date-picker",
            type: 'date',
            placeholder: '选择日期'
          }
        },
        state: {
          title: '状态',
          value: 'Y',
          component: {
            name: "el-switch",
            activeColor: "#13ce66",
            inactiveColor: "#ff4949",
            activeValue: "Y",
            inactiveValue: "N",
            activeText: '启用',
            inactiveText: '禁用',
          }
        }
      },
      columns: [{
          title: 'ID',
          key: 'id',
        },
        {
          title: '用户名',
          key: 'code',
        },
        {
          title: '姓名',
          key: 'name'
        },
        {
          title: '手机',
          key: 'mobile'
        },
        {
          title: '邮箱',
          key: 'mail'
        },
        {
          title: '生日',
          key: 'birthday',
          formatter: function(row, column, cellValue, index) {
            var date = row[column.property];
            if (date == undefined) {
              return "";
            }
            return dayjs(date).format("YYYY-MM-DD");
          }
        },
        {
          title: '状态',
          key: 'state',
          component: {
            name: "el-switch",
            activeColor: "#13ce66",
            inactiveColor: "#ff4949",
            activeValue: "Y",
            inactiveValue: "N",
            disabled: true
          }
        }
      ],
      rules: {
        code: [{
          required: true,
          message: '请输入用户名',
          trigger: 'blur'
        }],
        name: [{
          required: true,
          message: '请输入姓名',
          trigger: 'blur'
        }],
        mobile: [{
          validator: validMobile,
          trigger: ['blur', 'change']
        }],
        mail: [{
          type: 'email',
          message: '请输入正确的邮箱地址',
          trigger: ['blur', 'change']
        }]
      }
    }
  }
}
